/*
 * Powered By xTOOLs
 * Dev by tao.li8@pactera.com
 * Copyright ©2009-2018 pactera.com All rights reserved.
 *
 * Generated at 2020-7-20 10:33:35
 */

package com.pactera.jep.service.yapin.eval.value.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.pactera.jep.service.yapin.common.CommonPage;
import com.pactera.jep.service.yapin.eval.value.vo.AssessedEvalVo;
import com.pactera.jep.service.yapin.eval.value.vo.ExtlEvalVo;
import com.pactera.jep.service.yapin.eval.value.vo.ProcessListVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pactera.jep.orm.mybatis.mapper.Mapper;
import com.pactera.jep.orm.mybatis.service.MyBatisCRUDService;

import com.pactera.jep.service.yapin.eval.value.mapper.EvalProcessCltDetailsMapper;
import com.pactera.jep.service.yapin.eval.value.service.EvalProcessCltDetailsService;
import com.pactera.jep.service.yapin.eval.value.model.EvalProcessCltDetails;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务层实现
 * @author YourName
 * @date 2020-7-20 10:33:35
 */
@Service
@Transactional(readOnly = true)
public class EvalProcessCltDetailsServiceImpl extends MyBatisCRUDService<EvalProcessCltDetails, String> implements EvalProcessCltDetailsService {

    Logger logger =  LoggerFactory.getLogger(getClass());

    @Autowired
    private EvalProcessCltDetailsMapper			evalProcessCltDetailsMapper;

    @Override
    public Mapper<EvalProcessCltDetails, String> getMapper() {
         return evalProcessCltDetailsMapper;
    }

    @Override
    public int createOrUpdate(ExtlEvalVo extlEvalVo) {

        if(StringUtils.isBlank(extlEvalVo.getEvalProDetailsId())){
            //新增
            EvalProcessCltDetails evalProcessCltDetails = new EvalProcessCltDetails();
            BeanUtils.copyProperties(extlEvalVo,evalProcessCltDetails);
            //设置为首次评估
            evalProcessCltDetails.setIsFirstEval("Y");
            evalProcessCltDetailsMapper.insert(evalProcessCltDetails);
        }else {
            EvalProcessCltDetails evalProcessCltDetails = evalProcessCltDetailsMapper.selectByPrimaryKey(extlEvalVo.getEvalProDetailsId());
            if(evalProcessCltDetails != null){
                BeanUtils.copyProperties(extlEvalVo,evalProcessCltDetails);
                evalProcessCltDetailsMapper.updateSelective(evalProcessCltDetails);
            }
        }
        return 1;
    }

    @Override
    public int createAssessedEval(AssessedEvalVo assessedEvalVo) {
        EvalProcessCltDetails evalProcessCltDetails = evalProcessCltDetailsMapper.selectByPrimaryKey(assessedEvalVo.getEvalProDetailsId());
        if(evalProcessCltDetails != null){
            BeanUtils.copyProperties(assessedEvalVo,evalProcessCltDetails);
            evalProcessCltDetailsMapper.updateSelective(evalProcessCltDetails);
        }
        return 1;
    }
    @Override
    public Map<String, Object> getList(JSONObject object) {
        Map<String,Object> map = new HashMap<>();
        CommonPage commonPage = new CommonPage();
        commonPage.setPageNumber(object.getInteger("pageNumber"));
        commonPage.setPageSize(object.getInteger("pageSize"));
        commonPage.setStartRow(commonPage.getPageNumber(),commonPage.getPageSize());

        int total = evalProcessCltDetailsMapper.getListCount(object);
        List<ProcessListVo> rows = evalProcessCltDetailsMapper.getList(object,commonPage);

        map.put("total",total);
        map.put("rows",rows);
        return map;
    }
}
